home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / date / adinidb.int < prev    next >
Text File  |  1996-04-08  |  5KB  |  152 lines

  1. {$G+,X+,F+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   ADINIDB.PAS 1.01                    *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit AdIniDB;
  13.   {-Delphi INI database component}
  14.  
  15. interface
  16.  
  17. uses
  18.   {-----RTL}
  19.   SysUtils,
  20.   Classes,
  21.   Messages,
  22.   WinTypes,
  23.   DsgnIntf,
  24.   Forms,
  25.   Controls,
  26.   {-----APD}
  27.   OoMisc,
  28.   {$IFNDEF UseAPWDLL}
  29.   AwIniDB,
  30.   {$ENDIF}
  31.   AdMisc,
  32.   AdExcept,
  33.   AdDataB,
  34.   AdFldLst;
  35.  
  36. {$IFDEF UseAPWDLL}
  37. {$I AWINIDB.PA0}
  38. {$ENDIF}
  39.  
  40. const
  41.   DefDBName = 'DATABASE.INI';
  42.  
  43. type
  44.   {.Z+}
  45.   {property editor for list of database fields}
  46.   TDBFieldListProperty = class(TPropertyEditor)
  47.     procedure Edit; override;
  48.     function GetAttributes : TPropertyAttributes; override;
  49.     function GetValue : String; override;
  50.   end;
  51.  
  52.   {property editor for drop-down list of indexable fields}
  53.   TIndexedFieldProperty = class(TStringProperty)
  54.     function GetAttributes : TPropertyAttributes; override;
  55.     function GetEditLimit : Integer; override;
  56.     procedure GetValues(Proc : TGetStrProc); override;
  57.     procedure SetValue(const Value : String); override;
  58.   end;
  59.   {.Z-}
  60.  
  61.   {a database key string}
  62.   TDBKeyStr = String[MaxIndexLen];
  63.  
  64.   {INI database component}
  65.   TApdCustomIniDBase = class(TComponent)
  66.   protected {private}
  67.     {.Z+}
  68.     DB            : PIniDatabase;       {record passed to DLL calls}
  69.     FRecordList   : TStringList;        {for returning record lists}
  70.     FFieldList    : TDBFieldList;       {list of database fields}
  71.     Scratch       : Pointer;            {scratch record for passing into DLL}
  72.     Changed       : Boolean;            {TRUE if database data has changed}
  73.     FOpen         : Boolean;            {TRUE if database has been opened}
  74.     FFileName     : String;             {file name, used mostly at design time}
  75.     FIndexedField : TDBIndexedField;    {name of field used for index}
  76.     CustComponent : Boolean;
  77.  
  78.     {Property read/write methods}
  79.     procedure SetFileName(const NewName : String);
  80.       {-Update the database's file name.  If open, reopen with the new name}
  81.     procedure SetOpen(const OpenIt : Boolean);
  82.       {-Open or close the database}
  83.     procedure SetFieldList(const Fields : TDBFieldList);
  84.       {-Set the database's list of fields}
  85.     procedure SetIndexedField(const S : TDBIndexedField);
  86.       {-Set the name of the field used to index the database}
  87.     function GetRecordList : TStrings;
  88.       {-Returns the key strings for each record in the database}
  89.     function GetNumRecs : Integer;
  90.       {-Returns the number of records in the database}
  91.  
  92.     {utility}
  93.     procedure AssureOpen;
  94.       {-Make sure that the database is open, otherwise raise an exception}
  95.     procedure ClearFieldList;
  96.       {-Remove all fields in the field list}
  97.     procedure DefaultIndexed;
  98.       {-Default the FIndexedField property to the first indexable field in the list}
  99.  
  100.     {streaming}
  101.     procedure ReadFields(Reader : TReader);
  102.       {-Reads the database field list from a stream}
  103.     procedure WriteFields(Writer : TWriter);
  104.       {-Writes the database field list to a stream}
  105.     procedure DefineProperties(Filer : TFiler); override;
  106.       {-Define methods for reading and writing field list}
  107.  
  108.   protected
  109.     property FileName : String
  110.       read FFileName write SetFileName;
  111.     property FieldList : TDBFieldList
  112.       read FFieldList write SetFieldList;
  113.     property IndexedField : TDBIndexedField
  114.       read FIndexedField write SetIndexedField;
  115.  
  116.   public
  117.     {Creation/destruction}
  118.     constructor Create(AOwner : TComponent); override;
  119.     destructor Destroy; override;
  120.  
  121.     {.Z-}
  122.     function KeyExists(const Key : TDBKeyStr) : Boolean;
  123.       {-Return TRUE if an entry with an index of 'Name' exists}
  124.     procedure AddRecord(var Rec);
  125.       {-Add a record to the database}
  126.     procedure UpdRecord(const Key : TDBKeyStr; var Rec);
  127.       {-Update a record in the database}
  128.     procedure DelRecord(const Key : TDBKeyStr);
  129.       {-Remove a record from the database}
  130.     procedure GetRecord(const Key : TDBKeyStr; var Rec);
  131.       {-Get a record from the database}
  132.     procedure WriteToIni(var Rec; const Section, IniFile : String);
  133.       {-Write the record to a user-specified .INI file}
  134.     procedure ReadFromIni(var Rec; const Section, IniFile : String);
  135.       {-Read the record from a user-specified .INI file}
  136.  
  137.     property RecordList : TStrings
  138.       read GetRecordList;
  139.     property NumRecs : Integer
  140.       read GetNumRecs;
  141.     property Open : Boolean
  142.       read FOpen write SetOpen;
  143.   end;
  144.  
  145.   TApdIniDBase = class(TApdCustomIniDBase)
  146.   published
  147.     property FileName;
  148.     property FieldList;
  149.     property IndexedField;
  150.   end;
  151.  
  152.